struct Query{
string creature_name;
enum Argument{attack, defense} argument;
int result;
};
class Creature{
Game& game;
int attack, defense;
public:
string name;
};
int Creature::get_attach() const {
Query q{name, Query::Argument::attack, attack};
game.queries(q);
return q.result;
}
class CreatureModifier{
Game& game;
Creature& creature;
public:
CreatureModifier(Game& game, Creature& creature): game(game), creature(creature) {}
};
class DoubleAttackModifier: public CreatureModifier{
connection conn;
public:
DoubleAttackModifier(Game& game, Creature& creature): CreatureModifier(game, creature){
conn=gamequeries.connect([&](Query& q){
if(q.creature_name==creature.name &&
q.argument==Query::Argument::attack) q.result*=2;
});
}
~DoubleAttackModifier(){ conn.disconnect(); }
};
Game game;
Creature goblin{game, "Strong Goblin", 2, 2};
cout<<goblin<<endl;
{
DoubleAttackModifier dam{game, goblin};
cout<<goblin<<endl;
}
cout<<goblin<<endl;